package file_tab

import (
	"file_explorer/common/log"
	"file_explorer/common/util"
	"file_explorer/view/packed_widgets"
	"file_explorer/view/store"
)

type PathBar struct {
	*packed_widgets.HList

	tabCtx *store.FileTabContext
}

func NewPathBar(tabCtx *store.FileTabContext) *PathBar {
	pathBar := &PathBar{
		HList: packed_widgets.NewHList(
			0,
			func(index int) string {
				return tabCtx.DirNodes[index]
			},
			func() int {
				return len(tabCtx.DirNodes)
			}),
		tabCtx: tabCtx,
	}

	// 地址栏单击后退
	pathBar.OnTapped = func(col int) {
		newPath := util.PathJoin(pathBar.tabCtx.DirNodes[:col+1]...)
		log.Info("文件目录后退，路径：%s", newPath)
		pathBar.tabCtx.OpenDir(newPath)
	}

	return pathBar
}
